/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewJInternalFrame.java
 *
 * Created on 05/12/2011, 07:47:18 PM
 */
package appbastanteo1.view;

import appbastanteo1.BusinessException;
import appbastanteo1.model.Grupo;
import appbastanteo1.model.Poder;
import appbastanteo1.model.Cliente;
import appbastanteo1.model.Representante;
import appbastanteo1.controller.AdmGrupos;
import appbastanteo1.controller.AdmBastanteos;
import appbastanteo1.controller.AdmPoderes;
import appbastanteo1.controller.AdmClientes;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;

/**
 *
 * @author JuanJose.Fuchs
 */
public class VistaBastanteos extends javax.swing.JInternalFrame {

    private AdmBastanteos admBastanteos;
    private AdmGrupos admGrupos;
    private AdmPoderes admPoderes;
    private AdmClientes admClientes;
    private DefaultListModel modelo;
    private DefaultListModel modelofinal;

    /** Creates new form NewJInternalFrame */
    public VistaBastanteos(
            AdmBastanteos admBastanteos, AdmGrupos admGrupos,
            AdmPoderes admPoderes, AdmClientes admClientes) {
        initComponents();

        this.modelo = new DefaultListModel();
        this.modelofinal = new DefaultListModel();

        this.admBastanteos = admBastanteos;
        this.admGrupos = admGrupos;
        this.admPoderes = admPoderes;
        this.admClientes = admClientes;

        mostrarGrupos();
    }

    private void mostrarGrupos() {
        ArrayList<Grupo> grupos = admGrupos.getGrupos();
        cboGrupoPoderes.addItem("----------");
        for (Grupo grupo : grupos) {
            cboGrupoPoderes.addItem("" + grupo.getNombre());
        }
    }

    private void limpiar() {
        txtCliente.setText("");
        txtFechaVencimiento.setText("");
        txtImporte.setText("");
        txtRepresentante.setText("");
        cboGrupoPoderes.setSelectedIndex(0);
        cboTipoIntervencion.setSelectedIndex(0);
        modelo.removeAllElements();
        modelofinal.removeAllElements();
        listPoderes.setModel(modelo);
        listPoderesAgregados.setModel(modelofinal);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnQuitarTodosPoderes = new javax.swing.JButton();
        lblFechaVencimiento = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listPoderes = new javax.swing.JList();
        txtFechaVencimiento = new javax.swing.JFormattedTextField();
        txtImporte = new javax.swing.JTextField();
        lblImporte = new javax.swing.JLabel();
        btnBastantear = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        btnAgregarPoder = new javax.swing.JButton();
        cboTipoIntervencion = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        listPoderesAgregados = new javax.swing.JList();
        btnAgregartodosPoderes = new javax.swing.JButton();
        lblRepresentante = new javax.swing.JLabel();
        btnQuitarPoder = new javax.swing.JButton();
        txtRepresentante = new javax.swing.JTextField();
        txtCliente = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        btnBuscarCliente = new javax.swing.JButton();
        lblCliente = new javax.swing.JLabel();
        cboGrupoPoderes = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        btnBorrar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Bastantear Poderes");

        btnQuitarTodosPoderes.setText("<<");
        btnQuitarTodosPoderes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuitarTodosPoderesActionPerformed(evt);
            }
        });

        lblFechaVencimiento.setText("Fecha Vencimiento");

        jScrollPane2.setViewportView(listPoderes);

        txtFechaVencimiento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtFechaVencimientoActionPerformed(evt);
            }
        });

        txtImporte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtImporteActionPerformed(evt);
            }
        });

        lblImporte.setText("Importe");

        btnBastantear.setText("Bastantear");
        btnBastantear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBastantearActionPerformed(evt);
            }
        });

        jLabel3.setText("Tipo Intervencion");

        btnAgregarPoder.setText(">");
        btnAgregarPoder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregarPoderActionPerformed(evt);
            }
        });

        cboTipoIntervencion.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--------------", "A Sola Firma", "En Conjunto Con" }));
        cboTipoIntervencion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTipoIntervencionActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(listPoderesAgregados);

        btnAgregartodosPoderes.setText(">>");
        btnAgregartodosPoderes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregartodosPoderesActionPerformed(evt);
            }
        });

        lblRepresentante.setForeground(new java.awt.Color(51, 51, 255));
        lblRepresentante.setText("Representante");
        lblRepresentante.setOpaque(true);

        btnQuitarPoder.setText("<");
        btnQuitarPoder.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnQuitarPoderActionPerformed(evt);
            }
        });

        txtCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtClienteActionPerformed(evt);
            }
        });

        jLabel4.setText("Grupo Poderes");

        btnBuscarCliente.setText("Buscar");
        btnBuscarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarClienteActionPerformed(evt);
            }
        });

        lblCliente.setForeground(new java.awt.Color(51, 51, 255));
        lblCliente.setText("Cliente");
        lblCliente.setOpaque(true);

        cboGrupoPoderes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboGrupoPoderesItemStateChanged(evt);
            }
        });
        cboGrupoPoderes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboGrupoPoderesActionPerformed(evt);
            }
        });

        jLabel5.setText("Poderes");

        btnBorrar.setText("Limpiar");
        btnBorrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBorrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblRepresentante, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cboTipoIntervencion, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(txtRepresentante, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lblFechaVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(btnBuscarCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lblImporte, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(9, 9, 9))
                                    .addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtFechaVencimiento, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                                    .addComponent(txtImporte, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                                    .addComponent(btnBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnQuitarTodosPoderes, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnQuitarPoder, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnAgregartodosPoderes, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(btnAgregarPoder, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(147, 147, 147))
                            .addComponent(cboGrupoPoderes, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(246, 246, 246)
                        .addComponent(btnBastantear, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblCliente)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnBorrar)
                        .addComponent(btnBuscarCliente)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblRepresentante)
                    .addComponent(txtRepresentante, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtImporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblImporte))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cboTipoIntervencion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtFechaVencimiento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFechaVencimiento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(cboGrupoPoderes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnAgregarPoder, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnAgregartodosPoderes, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnQuitarPoder, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnQuitarTodosPoderes, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(30, 30, 30)
                .addComponent(btnBastantear, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(46, 46, 46))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnQuitarTodosPoderesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarTodosPoderesActionPerformed
        try {
            int x = listPoderes.getSelectedIndex();
     
            modelo.removeAllElements();
            for (int i = 0; i < modelofinal.size(); i++) {
                modelo.add(i, modelofinal.getElementAt(i));
            }
            listPoderes.setModel(modelo);
            modelofinal.removeAllElements();
            listPoderesAgregados.setModel(modelofinal);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "No se ha seleccionado ningun elemento");
        }
}//GEN-LAST:event_btnQuitarTodosPoderesActionPerformed

    private void txtFechaVencimientoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtFechaVencimientoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtFechaVencimientoActionPerformed

    private void txtImporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtImporteActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtImporteActionPerformed

    private void btnBastantearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBastantearActionPerformed
        if (admBastanteos.validarCampos(
                txtCliente.getText(),
                txtRepresentante.getText(),
                cboGrupoPoderes.getSelectedIndex(),
                cboTipoIntervencion.getSelectedIndex(),
                txtImporte.getText(),  
                txtFechaVencimiento.getText())) {

              try {
            DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            Date date = null;
            try {
                date = formatter.parse(txtFechaVencimiento.getText());
            } catch (ParseException ex) {

            }
            Cliente cli = admClientes.buscarClienteXNombre(txtCliente.getText());
            Representante rep = cli.getRepresentante();

            ArrayList<Poder> poderesxbastanteo = new ArrayList<Poder>();
            int x = listPoderesAgregados.getModel().getSize();
            for(int i = 0; i < listPoderesAgregados.getModel().getSize(); i++) {
                 System.out.println("____"+listPoderesAgregados.getModel().getElementAt(i));
                 poderesxbastanteo.add(admPoderes.buscarPoderesxNombre(listPoderesAgregados.getModel().getElementAt(i).toString()));
             }



            if (admBastanteos.bastanteoXPoderExiste(cli, rep, poderesxbastanteo)) {

                 admBastanteos.registrarBastanteo(cli, rep, cboTipoIntervencion.getSelectedItem().toString(),
                    poderesxbastanteo, date, Double.parseDouble(txtImporte.getText()));

            JOptionPane.showMessageDialog(this, "Bastanteo Grabado exitosamente");

            limpiar();
            System.out.println("cantidad de bastanteos: " + admBastanteos.cantidadBastanteos());
            }

            else{
            JOptionPane.showMessageDialog(this, "Ya existe un bastanteo con los datos o poderes registrados \n");
            }

        } catch (BusinessException ex) {
            JOptionPane.showMessageDialog(this, "Error al grabar elemento \n"+ ex.getMessage());
        }
        }
        else{
            JOptionPane.showMessageDialog(this, "Debe llenar los campos requeridos");
        }
}//GEN-LAST:event_btnBastantearActionPerformed

    private void btnAgregarPoderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregarPoderActionPerformed
        try {
            int x = listPoderes.getSelectedIndex();
            System.out.println("index: " + x);
            Object obj = modelo.getElementAt(x);
            modelo.removeElementAt(x);
            listPoderes.setModel(modelo);
            modelofinal.addElement(obj);
            listPoderesAgregados.setModel(modelofinal);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "No se ha seleccionado ningun elemento");
        }
}//GEN-LAST:event_btnAgregarPoderActionPerformed

    private void btnAgregartodosPoderesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregartodosPoderesActionPerformed
        try {
            int x = listPoderes.getSelectedIndex();
            modelofinal.removeAllElements();
            for (int i = 0; i < modelo.size(); i++) {
                modelofinal.add(i, modelo.getElementAt(i));
            }
            listPoderesAgregados.setModel(modelofinal);
            modelo.removeAllElements();
            listPoderes.setModel(modelo);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "No se ha seleccionado ningun elemento");
        }
}//GEN-LAST:event_btnAgregartodosPoderesActionPerformed

    private void btnQuitarPoderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarPoderActionPerformed
        try {
            int x = listPoderesAgregados.getSelectedIndex();
            System.out.println("index: " + x);
            Object obj = modelofinal.getElementAt(x);
            modelofinal.removeElementAt(x);
            modelo.addElement(obj);
            listPoderes.setModel(modelo);
            listPoderesAgregados.setModel(modelofinal);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "No se ha seleccionado ningun elemento");
        }
}//GEN-LAST:event_btnQuitarPoderActionPerformed

    private void txtClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtClienteActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtClienteActionPerformed

    private void btnBuscarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarClienteActionPerformed
        Cliente cliente = admClientes.buscarCliente(txtCliente.getText());
        if (cliente != null) {
            txtCliente.setText(cliente.getRazonSocial());
            Representante rep = cliente.getRepresentante();
            txtRepresentante.setText(rep.getNombres() + " " + rep.getApellidos());
            txtCliente.setEditable(false);
            txtRepresentante.setEditable(false);

        } else {
            JOptionPane.showMessageDialog(this, "No se ha encontrado el cliente con los datos ingresados");
        }
}//GEN-LAST:event_btnBuscarClienteActionPerformed

    private void cboGrupoPoderesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboGrupoPoderesItemStateChanged
        if (!cboGrupoPoderes.getSelectedItem().toString().startsWith("---")) {
             modelo.removeAllElements();
        System.out.println("Entro al itemstatechanged");
        Grupo grupo = new Grupo();
        grupo = admGrupos.obtenerGrupo(cboGrupoPoderes.getSelectedItem().toString());
        ArrayList<Poder> array = new ArrayList<Poder>();
        array = admPoderes.getPoderesxGrupo(grupo);

        System.out.println("Tamaño del array " + array.size());
        for (int i = 0; i < array.size(); i++) {
            modelo.add(i, array.get(i).getNombre());
        }
        listPoderes.setModel(modelo);
        }
    }//GEN-LAST:event_cboGrupoPoderesItemStateChanged

    private void cboGrupoPoderesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboGrupoPoderesActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cboGrupoPoderesActionPerformed

    private void btnBorrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBorrarActionPerformed
        txtCliente.setEditable(true);
        txtRepresentante.setEditable(true);
        txtCliente.setText("");
        txtRepresentante.setText("");
    }//GEN-LAST:event_btnBorrarActionPerformed

    private void cboTipoIntervencionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboTipoIntervencionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboTipoIntervencionActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregarPoder;
    private javax.swing.JButton btnAgregartodosPoderes;
    private javax.swing.JButton btnBastantear;
    private javax.swing.JButton btnBorrar;
    private javax.swing.JButton btnBuscarCliente;
    private javax.swing.JButton btnQuitarPoder;
    private javax.swing.JButton btnQuitarTodosPoderes;
    private javax.swing.JComboBox cboGrupoPoderes;
    private javax.swing.JComboBox cboTipoIntervencion;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblCliente;
    private javax.swing.JLabel lblFechaVencimiento;
    private javax.swing.JLabel lblImporte;
    private javax.swing.JLabel lblRepresentante;
    private javax.swing.JList listPoderes;
    private javax.swing.JList listPoderesAgregados;
    private javax.swing.JTextField txtCliente;
    private javax.swing.JFormattedTextField txtFechaVencimiento;
    private javax.swing.JTextField txtImporte;
    private javax.swing.JTextField txtRepresentante;
    // End of variables declaration//GEN-END:variables
}
